﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Event.NCL;
using CPPEI.Coolzon.Service.Contract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.Views.EventProxies
{
    public class LoginHandler : BaseResponseHandler<Service.Contract.RespLoginData>
    {
        protected override void OnHandle(RemoteEventProxy remoteEventProxy, ServiceProxy.MainServiceRef.Response response, RespLoginData responseData)
        {
            NCLLoginEvent @event = new NCLLoginEvent();
            if (responseData.IsSuccess)
            {
                @event.State = NCLEventState.Finished;
                @event.Result = new NCLLoginEvent.EventResult();
                @event.Result.UserAccount = responseData.UserIdentity;
                @event.Result.UserIdentity = responseData.UserIdentity;
                @event.Result.UserName = responseData.UserName;
                NCLEventBus.PublishAsync(@event);
            }
            else
            {
                @event.State = NCLEventState.Failure;
                @event.Error = new Exception(responseData.Message);
                NCLEventBus.PublishAsync(@event);
            }
        }
    }
}
